﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OneRed.Draw
{
    /// <summary>
    /// ForceDirectMap.xaml 的交互逻辑
    /// </summary>
    public partial class ForceDirectMap : UserControl
    {
        public static ObservableCollection<Node> Nodes { get; set; }
        public static ObservableCollection<Edge> Edges { get; set; }

        public static Params Param { get; set; }

        public ForceDirectMap()
        {
            InitializeComponent();
            DataContext = this;
        }

        private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {
            UIElement thumb = e.Source as UIElement;
            var vc = ((VisualTreeHelper.GetParent(thumb)) as ContentPresenter).Content as Node;
            Guid NodeId = vc.NodeId;
            var vx = vc.Xp;
            var vy = vc.Yp;

            var vH = e.HorizontalChange;
            var vV = e.VerticalChange;

            vc.Xp = vx + vH;
            vc.Yp = vy + vV;

            var vEdges = Edges.Where(e => e.From.NodeId == NodeId || e.To.NodeId == NodeId).ToList();
            foreach (Edge ed in vEdges)
            {
                ed.Opacity = 0.5;
            }
        }
    }
}
